package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DayData;
import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.dto.HealthyDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.service.IFamilyMemberService;

import static com.zzyl.nursing.vo.ApiResponse.*;

/**
 * 老人家属Controller
 *
 * @author 陈舜涛
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public AjaxResult login(@RequestBody @ApiParam("登录参数") UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }


    @PostMapping("/add")
    @ApiOperation("添加")
    public AjaxResult add(@RequestBody FamilyMemberDto familyMemberDto, HttpServletRequest request) {
        familyMemberService.add(familyMemberDto, request);
        return success();
    }

    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult my() {
        List<FamilyMemberElderVo> familyMemberList = familyMemberService.selectFamilyMemberList();
        return success(familyMemberList);
    }

    @GetMapping("/list-by-page")
    @ApiOperation("分页查询")
    public AjaxResult listByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 HttpServletRequest request) {
        return success(familyMemberService.listByPage(pageNum, pageSize, request));
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody HealthyDataDto healthyDataDto) {
        List<HealthyDataVo> healthyDataVos = familyMemberService.QueryDevicePropertyStatus(healthyDataDto);
        ResultInfo re = new ResultInfo(healthyDataVos);
        Result result = new Result(re);
        return success(result);
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public AjaxResult queryDeviceDataListByDay(String functionId, Long startTime, Long endTime, String iotId){
        List<DayData> dayData = familyMemberService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return success(dayData);
    }
    //解绑家人
    @DeleteMapping("/deleteById")
    @ApiOperation("解绑家人")
    public AjaxResult deleteById(@RequestParam("id") Long id) {
        familyMemberService.deleteFamilyMemberById(id);
        return success();
    }


    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public AjaxResult queryDeviceDataListByWeek(String functionId, Long startTime, Long endTime, String iotId){
        List<DayData> dayData = familyMemberService.queryDeviceDataListByWeek(functionId, startTime, endTime, iotId);
        return success(dayData);
    }
}
